package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要新增图书的书名：");
        String name = scanner.nextLine();
        System.out.println("请输入你要新增图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入你要新增图书的类型：");
        String type = scanner.nextLine();
        System.out.println("请输入你要新增图书的价格：");
        int price  = scanner.nextInt();
        //构造book对象并存放
        Book book = new Book(name,author,type,price);
        int currentSize = bookList.getUsedSize();
        for (int i = 0;i<currentSize;i++){
            Book tmp = bookList.getBooks(i);
            if (tmp.getName().equals(name)){//book.getName是什么 name是什么
                System.out.println("存在这本书，信息如下");
                System.out.println(book);
                return;
            }
        }
        //没有重复的书，开始新增
        bookList.setBooks(book,currentSize);
        System.out.println("新增成功！ 新增书的信息如下：");
        System.out.println(book);
        bookList.setUsedSize(currentSize+1);
    }
}
